package com.songshuai.customer.client.controller;

import com.songshuai.customer.client.dto.request.InvitationRecord.AddInvitationRecordReqDto;
import com.songshuai.customer.client.service.InvitationRecordService;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.exception.BusinessException;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import com.songshuai.webapi.baseapi.utils.SnowFlakeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

/**
 * @Author:wbl
 * @Date: 2019/3/27
 */
@Slf4j
@Api("邀请记录")
@RestController
@RequestMapping("/api/cust/invitationrecord/")
public class InvitationRecordController extends BaseController{

    @Autowired
    private InvitationRecordService invitationRecordService;

    @ApiOperation(value = "新增邀请记录")
    @PostMapping("addInvitationRecord")
    public CompletableFuture<QueryResponse> addInvitationRecord(@RequestBody AddInvitationRecordReqDto parm){
        String openId = getCurrentCustomerOpenid();
        String customId = getCurrentcustomerId();
        if(StringUtils.isBlank(openId) || StringUtils.isBlank(customId)){
            throw new BusinessException(ResultStatus.NO_LOGIN.getErrorMsg(), ResultStatus.FAIL);
        }
        return CompletableFuture.supplyAsync(() ->{
            invitationRecordService.addInvitationRecord(customId,parm);
            return QueryResponse.setResData(null);
        });
    }
}
